<%@page import="Test.TestPaper"%>
<%@page import="java.util.ArrayList"%>
<%@page import="Test.TestPaperState"%>
<%@page import="java.util.Iterator"%>
<%@page import="Test.Course"%>
<%@page import="DBModule.TestPaperManager"%>
<%@page import="java.util.Collection"%>
<%@ page import="User.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择要考的科目</title>
<link rel="stylesheet" href="css/default.css" type="text/css" />
</head>
<body bgcolor="silver">
<center>
<%
	try{
		User user = (User)session.getAttribute("user");
		if (user == null) {
			response.sendRedirect("index.jsp");
			return;
		}

		// 所有科目情况
		Collection<TestPaperState> set = TestPaperManager.getAllState(user);
		
		// 显示之
%>
	<br/><h2>欢迎登陆，<%=user.getName()%>同学
	<br/>您的所有考试情况</h2><br/>
	<table border="1">
		<tr><th>科目</th><th>当前状态</th><th>得分</th></tr>
<%
	String[] stateName = {"未作答", "正在审阅", "审阅完毕"};
		for (Iterator<TestPaperState> iter = set.iterator(); iter.hasNext();){
	TestPaperState state = iter.next();
	out.print("<tr><td>" + state.getCourse() + "</td><td>");
	out.print(stateName[state.getState()] + "</td><td>");
	out.print(state.getScore() + "</td></tr>");
		}
%>
	</table>

<%

%>
	<form method="post" action="TestServlet?method=select">
		<br/>请选择科目作答：
		<select name="course">
<%
		Iterator<TestPaperState> iter = set.iterator();
		while (iter.hasNext()){
			TestPaperState state = iter.next();
			if (state.getState() != TestPaper.UNSOLVED) continue;
			Course course = state.getCourse();
%>
			<option value="<%=course.getId() %>"><%=course.getName()%></option>
<%
		}
%>	
		</select>
		<input type="submit" value="选择该科目">
	</form>
<%
	}
	catch (Exception e){
		session.setAttribute("alert", e.getMessage());
		response.sendRedirect("alert.jsp");
		return;
	}
		
%>
</center>
</body>
</html>